﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using CoreEx.Common.Implementation.Linq;

namespace CoreEx.Database.Linq
{
    public static class ExpressionExtensions
    {
        public static LambdaExpression Evaluate(this LambdaExpression target)
        {
            return (LambdaExpression)Evaluator.PartialEval(target);
        }

        public static Expression StripQuotes (this Expression target)
        {
            while (target.NodeType == ExpressionType.Quote || target.NodeType == ExpressionType.Convert)
            {
                target = ((UnaryExpression)target).Operand;
            }
            return target;
        }


        public static bool IsQueryable(this ConstantExpression constantExpression)
        {
            return typeof (IQueryable).IsAssignableFrom(constantExpression.Value.GetType());
        }



    }
}
